//package com.bcmusic.order.listener;
//
//import com.alibaba.fastjson.JSON;
//import com.bcmusic.order.config.TokenDecode;
//import com.bcmusic.order.pojo.Orders;
//import com.bcmusic.order.service.OrdersService;
//import com.bcmusic.pay.feign.WeixinPayFeign;
//import com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionWsaServerTube;
//import entity.Result;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.messaging.handler.annotation.Payload;
//import org.springframework.stereotype.Component;
//
//import java.util.Map;
//
///**
// * @ClassName : OrderDelayMessageListener  //类名
// * @Description :   //描述
// * @Author : YG  //作者
// * @Date: 2020-10-14 19:58  //时间
// */
//@Component
//@RabbitListener(queues = {"${mq.pay.queue.ordertimer}"})
//public class OrderDelayMessageListener {
//    @Autowired
//    private RedisTemplate redisTemplate;
//    @Autowired
//    private OrdersService ordersService;
//    @Autowired
//    private WeixinPayFeign weixinPayFeign;
//
//    /**
//     * 回滚库存，删除订单
//     */
//    @RabbitHandler
//    public void backout(@Payload String message) throws Exception {
//        //读取消息
//        Orders orders= JSON.parseObject(message, Orders.class);
//
//        //获取Redis中订单信息
//        Integer orderId = orders.getOrderId();
//        Orders orderRedis = (Orders)redisTemplate.boundHashOps("Order").get(orderId);
//        //如果Redis中有订单信息，说明用户未支付
//        if(orderRedis!=null){
//            //关闭支付
//            Result closeResult = weixinPayFeign.closePay(orders.getOrderId());
//            Map<String,String> closeMap = (Map<String, String>) closeResult.getData();
//            if(closeMap!=null && closeMap.get("return_code").equalsIgnoreCase("success") &&
//                    closeMap.get("result_code").equalsIgnoreCase("success") ){
//                //关闭订单
//                String userNum = orders.getUserNumber();
//                ordersService.unPay(orders.getOrderId());
//                String outtradeno=closeMap.get("out_trade_no");
//                //redis删除订单
//                redisTemplate.boundHashOps("orders").delete(Integer.valueOf(outtradeno));
//            }
//        }
//    }
//}
